package com.guoranhao.web.resolver;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * Description: Jackson序列烦序列化Mapper配置
 * All Rights Reserved.
 * @version 1.0  2016年12月22日 下午4:18:56  by 代鹏（daipeng.456@gmail.com）创建
 */
@Component("jacksonObjectMapper")
public class CustomObjectMapper extends ObjectMapper {

    private static final long serialVersionUID = 1L;

    @PostConstruct
    public void afterPropertiesSet() {
        setSerializationInclusion(JsonInclude.Include.NON_NULL);
        disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
        disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
        enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
    }
}
